﻿using MLog.Helpers;
using UnityEngine;

namespace MLog.Core.Appender {
    public class FileAppender : BaseAppender<LoggerEvent> {
        public string Dir { set; get; }
        public string BaseName { set; get; }

        public LoggerWorker Worker { get; set; }

        protected override void DoAppend0(LoggerEvent @event) {
            var data = FormatterUtils.Format(@event, Pattern);
            Worker.Put(data);
        }

        public override void ApplyConfig(Node config) {
            base.ApplyConfig(config);
            Worker = Workers.GetOrCreateWorker(Dir, BaseName);
        }
    }
}